package com.yic.module.wms.dal.mysql.warehouselocation;

import java.util.*;

import com.yic.framework.common.pojo.PageResult;
import com.yic.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.yic.framework.mybatis.core.mapper.BaseMapperX;
import com.yic.module.wms.dal.dataobject.warehouselocation.WarehouseLocationDO;
import org.apache.ibatis.annotations.Mapper;
import com.yic.module.wms.controller.admin.warehouselocation.vo.*;

/**
 * 库位 Mapper
 *
 * @author 系统管理员
 */
@Mapper
public interface WarehouseLocationMapper extends BaseMapperX<WarehouseLocationDO> {

    default PageResult<WarehouseLocationDO> selectPage(WarehouseLocationPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<WarehouseLocationDO>()
                .eqIfPresent(WarehouseLocationDO::getWarehouseId, reqVO.getWarehouseId())
                .eqIfPresent(WarehouseLocationDO::getAreaId, reqVO.getAreaId())
                .likeIfPresent(WarehouseLocationDO::getName, reqVO.getName())
                .eqIfPresent(WarehouseLocationDO::getCode, reqVO.getCode())
                .eqIfPresent(WarehouseLocationDO::getStatus, reqVO.getStatus())
                .orderByDesc(WarehouseLocationDO::getId));
    }

    default List<WarehouseLocationDO> selectList(WarehouseLocationExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<WarehouseLocationDO>()
                .eqIfPresent(WarehouseLocationDO::getWarehouseId, reqVO.getWarehouseId())
                .eqIfPresent(WarehouseLocationDO::getAreaId, reqVO.getAreaId())
                .likeIfPresent(WarehouseLocationDO::getName, reqVO.getName())
                .eqIfPresent(WarehouseLocationDO::getCode, reqVO.getCode())
                .eqIfPresent(WarehouseLocationDO::getStatus, reqVO.getStatus())
                .orderByDesc(WarehouseLocationDO::getId));
    }

    default List<WarehouseLocationDO> selectListByAreaId(Long id) {
        return selectList(new LambdaQueryWrapperX<WarehouseLocationDO>()
                .eq(WarehouseLocationDO::getAreaId, id));
    }

    default WarehouseLocationDO selectByCode(String code) {
        return selectOne(new LambdaQueryWrapperX<WarehouseLocationDO>()
                .eq(WarehouseLocationDO::getCode, code));
    }

    default List<WarehouseLocationDO> selectList(Collection<Long> ids, Long areaId, Collection<Integer> status) {
        return selectList(new LambdaQueryWrapperX<WarehouseLocationDO>()
                .inIfPresent(WarehouseLocationDO::getId, ids)
                .eqIfPresent(WarehouseLocationDO::getAreaId, areaId)
                .inIfPresent(WarehouseLocationDO::getStatus, status));
    }
}
